{template "header.html"}
<div class="note note-danger">
    <p>如有特别需求可以联系QQ：187013488 <a target="_blank" href="//shang.qq.com/wpa/qunwpa?idkey=04e194787e3b0d607da8016ed7211d2fb9b75e56efdb6697f791d7b2ee132102"><img border="0" src="//pub.idqqimg.com/wpa/images/group.png" alt="交流群" title="交流群"></a></p>
</div>
<style>
.labmr10{ margin-right: 10px; }
.labtxt{color: #999;}
.dis,#moshi_row,#field_row{ display: none }
textarea.form-control{  }
.CodeMirror-wrap{ border-radius: 6px; overflow: hidden; }
</style>

<link href="{THEME_PATH}assets/global/plugins/codemirror/lib/codemirror.css" rel="stylesheet" type="text/css" />
<link href="{THEME_PATH}assets/global/plugins/codemirror/theme/material.css" rel="stylesheet" type="text/css" />

<script src="{THEME_PATH}assets/global/plugins/codemirror/lib/codemirror.js" type="text/javascript"></script>
<script src="{THEME_PATH}assets/global/plugins/codemirror/mode/javascript/javascript.js" type="text/javascript"></script>

<script src="{THEME_PATH}assets/global/plugins/codemirror/mode/xml/xml.js" type="text/javascript"></script>

<!-- 因为HTML混合语言依赖Javascript、XML、CSS语言支持，所以都要引入 -->
<script src="{THEME_PATH}assets/global/plugins/codemirror/addon/edit/matchbrackets.js"></script>
<script src="{THEME_PATH}assets/global/plugins/codemirror/addon/selection/active-line.js"></script>
<script src="{THEME_PATH}assets/global/plugins/codemirror/addon/selection/selection-pointer.js"></script>

<script src="{THEME_PATH}assets/global/plugins/codemirror/mode/xml/xml.js"></script>
<script src="{THEME_PATH}assets/global/plugins/codemirror/mode/javascript/javascript.js"></script>
<script src="{THEME_PATH}assets/global/plugins/codemirror/mode/css/css.js"></script>
<script src="{THEME_PATH}assets/global/plugins/codemirror/mode/htmlmixed/htmlmixed.js"></script>
<div class="row">
<div class="col-md-6 col-sm-6">


    <div class="portlet light bordered myportlet ">
        <div class="portlet-title tabbable-line">
            <div class="caption">
                <span class="caption-subject font-green-sharp">
                <i class="fa fa-cog"></i> 栏目调用</span>
            </div>
        </div>


        <div class="portlet-body form">
            <form class="form-horizontal" id="myform_2">
                {dr_form_hidden()}
                <div class="form-body">
                    <div class="form-group">
                        <label class="col-md-2 control-label">调用模式</label>
                        <div class="col-md-10">
                            <label class="labmr10">
                                <select class="form-control" name="moshi" id="moshi" onchange="single_cat(this);">
                                    <option value="">选择模式</option>
                                        <option value="1">单独调用</option>
                                        <option value="2">循环栏目</option>
                                </select>
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">模块</label>
                        <div class="col-md-10">
                            <label class="labmr10">
                                <select class="form-control" name="module" id="module" onchange="single_cat(this);">
                                    <option value="">选择模块</option>
                                    {loop $module $dir $m}
                                        <option value="{$dir}">{$m.name}</option>
                                    {/loop}
                                </select>
                            </label>
                            <label>栏目</label>
                            <label class="labmr10">
                                <select class="form-control" name="catid" id="catid" onchange="single_cat(this);">
                                    <option value="">选择栏目</option>
                                </select>
                            </label>
                        </div>
                    </div>
                    <div class="form-group" id="moshi_row">
                        <label class="col-md-2 control-label">记录数</label>
                        <div class="col-md-10">
                            <label class="labmr10"><input class="form-control " type="text" name="num" value="10" style="width:80px;" /></label>
                            <label>缓存时间</label>
                            <label class="labmr10"><input class="form-control " type="text" name="cache" value="3600" style="width:80px;" /></label>
                            <label>变量</label>
                            <label class="labmr10"><input class="form-control " type="text" name="return" value="t" style="width:80px;" /></label>
                        </div>
                    </div>
                    <div class="form-group" id="field_row">
                        <label class="col-md-2 control-label">栏目字段</label>
                        <div class="col-md-10">
                            <label class="labmr10">
                                <select class="form-control" name="field" id="field">
                                    <option value="">选择字段</option>
                                </select>
                            </label>
                        </div>
                    </div>
                </div>
                <div class="form-actions">
                    <div class="row">
                        <div class="col-md-offset-2 col-md-9">
                            <button type="button" id="2" class="btn green">生成标签</button>
                            <a href="javascript:dr_help_labe(623);" class="btn default">单独调用手册</a>
                            <a href="javascript:dr_help_labe(389);" class="btn default">循环手册</a>
                            <a href="javascript:dr_help_labe(102);" class="btn default">字段输出</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>


</div>





    <div class="col-md-6 col-sm-6">
        <div class="portlet light bordered myportlet copyinput">

            <div class="portlet-title tabbable-line">
                <div class="caption">
                    <i class="fa fa-cog"></i>
                    <span class="caption-subject">生成</span>
                </div>
            </div>
            <div class="portlet-body form form-horizontal">
                <div class="form-body" id="listlab">


                    <div class="form-group">
                        <div class="col-md-12">
                            <textarea id="labelling" class="form-control" rows="30" name="labelling" ></textarea>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>

</div><!--row-->












<script>
var mixedMode = {
    name: "htmlmixed",
    scriptTypes: [{
            matches: /\/x-handlebars-template|\/x-mustache/i,
            mode: null
        },
        {
            matches: /(text|application)\/(x-)?vb(a|script)/i,
            mode: "vbscript"
        }
    ]
};
var editor = CodeMirror.fromTextArea(document.getElementById("labelling"), {
    mode: mixedMode,
    selectionPointer: true,
    lineNumbers: true,
    lineWrapping: true, // 自动换行
    styleActiveLine: true,
    theme: 'material', // 使用monokai模版
    matchBrackets: true
});
editor.setSize('auto','595px');
</script>

<script>
function single_cat(select){

    if(select.id=='moshi'){
        if(select.value==2){
            $('#moshi_row').show();
            $('#field_row').hide();
        }else{
            $('#moshi_row').hide();
            $('#field_row').show();
        }
    }


    if(select.id=='module'){
        $('#catid').empty();
        $('#field').empty();
        //$('#field optgroup').remove();
        //
        var moshi = $("#moshi").val();

        $.ajax({
            type: "POST",
            dataType: "json",
            url: '{dr_url("labelling/home/catstree")}',
            data: {moshi:moshi,module: select.value, {csrf_token()}: "{csrf_hash()}"},

            success: function(json) {
                if (json.code == 1) {
                    $('#catid').append(json.msg);
                    $('#field').append(json.data);
                } else {
                    dr_cmf_tips(0, json.msg);
                }
                return false;
            },
            error: function(HttpRequest, ajaxOptions, thrownError) {
                dr_ajax_alert_error(HttpRequest, ajaxOptions, thrownError)
            }
        });

    }

    console.log(select.id);
    //alert(this.id);
}


$(".form button").click(function() {
    var id = $(this).attr('id');
    var textarea = '#myform_'+id+' #labelling';
    var form = '#myform_' + id;
    $.ajax({
        type: "POST",
        dataType: "json",
        url: '{dr_url("labelling/home/labelling")}&id=' + id,
        data: $(form).serialize(),
        success: function(json) {
            if (json.code == 1) {
                //$(textarea).html(json.msg);
$(textarea).empty();
$(textarea).text(json.msg);
editor.getDoc().setValue(json.msg);
editor.refresh();
            } else {
                //$(textarea).html(json.data);
$(textarea).empty();
$(textarea).text(json.msg);
editor.getDoc().setValue(json.msg);
editor.refresh();
                dr_cmf_tips(0, json.msg);
            }
            return false;
        },
        error: function(HttpRequest, ajaxOptions, thrownError) {
            dr_ajax_alert_error(HttpRequest, ajaxOptions, thrownError)
        }
    });

    //console.log("click");
});
</script>
<script type="text/javascript">
    function dr_help_labe(id) {
        if (is_oemcms == 1) {
            dr_tips(1, '请联系开发商');
            return;
        }
        layer.open({
            type: 2,
            title: '<i class="fa fa-question-circle"></i> 在线帮助',
            shadeClose: true,
            scrollbar: false,
            shade: 0,
            area: ['80%', '90%'],
            content: 'https://www.xunruicms.com/index.php?s=doc&c=show&id='+id+'&is_phpcmf=cms'
        });
    }
</script>
{template "footer.html"}